#!/bin/sh /etc/rc.common

START=99

USE_PROCD=1
PROG=/usr/bin/respondd
NAME=respondd


multicast_group()
{
	config_get group "$1" group
	config_get interfaces "$1" interface
	config_get disabled "$1" disabled 0

	if [ "$disabled" -gt "0" ]; then
		return
	fi

	procd_append_param command -g $group
	for iface in "$interfaces"; do
		procd_append_param command -i "$iface"
	done
}

daemon_settings()
{
	config_get port "$1" port
	config_get providers "$1" providers

	procd_append_param command -p "$port"
	procd_append_param command -d "$providers"
}

start_service()
{
	. /lib/functions.sh
	. /lib/functions/network.sh

	procd_open_instance
	procd_set_param command "$PROG"

	config_load respondd
	config_foreach daemon_settings daemon
	config_foreach multicast_group multicast-group

	procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
	procd_set_param stderr 1
	procd_close_instance
}

service_triggers()
{
	procd_add_config_trigger "config.change" "respondd" /etc/init.d/respondd reload
	procd_add_interface_trigger "interface.*" 2000 /etc/init.d/respondd reload
}
